package com.tuanzi.loan.business.repository.family.impl;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanIcpSensitiveKeyword.LOAN_ICP_SENSITIVE_KEYWORD;

import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.tuanzi.loan.business.repository.family.IcpWebSensitiveKeywordRepository;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.family.IcpWebSensitiveKeywordSearchRequest;
import com.tuanzi.loan.vo.response.family.IcpWebSensitiveKeywordSearchResponse;

/**
 * ICP备案网站敏感词 JOOQRepository 实现
 * @author JinRuiyang 2017/12/13 18:09:02
 */
@Repository
public class IcpWebSensitiveKeywordRepositoryImpl extends JOOQBaseRepository implements IcpWebSensitiveKeywordRepository {

    /**
     * IcpWebSensitiveKeyword查询
     *
     * @param searchRequest 请求信息
     * @param pageable      分页信息
     * @return 响应列表
     */
    @Override
    public Page<IcpWebSensitiveKeywordSearchResponse> list(IcpWebSensitiveKeywordSearchRequest searchRequest, Pageable pageable) {

        contains(LOAN_ICP_SENSITIVE_KEYWORD.KEYWORD,searchRequest.getKeyword());
        eq(LOAN_ICP_SENSITIVE_KEYWORD.IS_ENABLE,1);

        return search(pageable,record -> {
            IcpWebSensitiveKeywordSearchResponse response = new IcpWebSensitiveKeywordSearchResponse();
            response.setId(record.get(LOAN_ICP_SENSITIVE_KEYWORD.ID));
            response.setPk(record.get(LOAN_ICP_SENSITIVE_KEYWORD.ID));
            response.setKeyword(record.get(LOAN_ICP_SENSITIVE_KEYWORD.KEYWORD));
            response.setStatus(record.get(LOAN_ICP_SENSITIVE_KEYWORD.STATUS,Integer.class));
            response.setIsEnable(record.get(LOAN_ICP_SENSITIVE_KEYWORD.IS_ENABLE,Integer.class));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_ICP_SENSITIVE_KEYWORD;
    }
}
